/*
 * SocketMsgSender.cpp
 * Consumer class to send data to specified socket in separated thread.
 *  Created on: 19/06/2011
 *      Author: wadi
 */

#include "socketmsgsender.h"


SocketMsgSender::SocketMsgSender(BlockingQueue* msgQueue,Socket* socketToSend):logger_(log4cxx::Logger::getLogger("common.comm.socketmsgsender"))
{
	closed=false;
	queue=msgQueue;
	socket=socketToSend;
}

SocketMsgSender::~SocketMsgSender()
{
}

void SocketMsgSender::close(){
	closed=true;
}

void SocketMsgSender::run(){
	LOG4CXX_TRACE(logger_, "running socket sender");
	while(!closed){
		LOG4CXX_TRACE(logger_, "Taking from queue");
		std::vector<char> msg=queue->take();
		if(msg.size()>0)
		if(!closed){
			LOG4CXX_TRACE(logger_, "Toked msg with size: "<<msg.size());
			socket->escribir(&msg.at(0),msg.size());
		}
	}
}
